<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../static/userinfoPrivate/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../static/css/thesame.css" media="all">
    <link rel="stylesheet" href="../static/css/footer.css" media="all">
    <link rel="stylesheet" href="../static/css/drugs/rightCon.css" media="all">
    <link rel="stylesheet" href="../static/css/drugs/page.css" media="all">
    <link rel="stylesheet" type="text/css" th:href="@{/static/css/organization/healthPopCss.css}" media="all"/>
</head>

<body class="layui-layout-body">
<div class="layui-body">
    <div class="add-title pad25px"><span class="mr10px cursor return"><img src="../static/img/return_icon.png"></span><span>查看药物登记</span></div>
    <div class="new-add-box bgWhite box-shadows border-radius4">
        <div class="add-box-scroll">
            <div class="border-bot5px border-radius4 pad25px">
                <dl class="per-look-dl">
                    <dt><img src="" id="headUrl" class="block"></dt>
                    <dd>
                        <div class="overflow">
                            <p class="left">
                                <span id="userName"></span>
                                <span class="border-bggray" id="bedInfo"></span>
                            </p>
                            <p class="right">
                                <span class="border-bgred cursor" id="cognitionStatus" style="display: none">认知问题</span>
                                <span class="border-bgred cursor" onclick="nursingLevelPicLayerOpen()">
											<em id="nursingDegree"></em>
											<em class="look-em border-bgred textCenter">?</em>
                                </span>
                                <span class="border-bgred" id="assessmentDegree"></span>
                            </p>
                        </div>
                        <div>
                            <span id="userSex"></span>
                            <span id="userAge"></span>
                            <span id="eduction"></span>
                            <span id="securityType"></span>
                            <span id="userAddress"></span>
                        </div>
                        <div>
                            <span class="border-bggreen" id="contractEndDate"></span>
                            <span class="border-bggreen" id="assessmentDate"></span>
                            <span class="border-bggreen" id="nursingDate"></span>
                        </div>
                    </dd>
                </dl>
            </div>
            <div>
                <div class="layui-tab layui-tab-time" style="margin: 10px 0 0;">
                    <div class="layui-form">
                        <ul class="layui-tab-title pl25px mei">
                            <li class="layui-this" id="3" value="1">药物库</li>
                            <li id="4" value="2">药物发放</li>
                        </ul>
                    </div>
                    <div class="layui-tab-content bgWhite pad25px mei">
                        <div class="layui-tab-item layui-show" id="1">
                            <!-- 药物库-查看 -->
                            <article>
                                <div class="lh32px mb20px overflow add-btn-input">
                                    <p class="left cursor">
                                        <span class="white border-radius4 bgGreen inline-block pl15px pr15px" onclick="register()"><img src="../static/img/button_add.png">添加药物</span>
                                        <span class="white border-radius4 bgGreen inline-block pl15px pr15px mr25px ml25px" onclick="downloadRegExcel()"><img src="../static/css/staff/img/icon_daochu.png">下载自备药品登记表</span>
                                    </p>
                                    <p class="right" id="c1">
                                        <span>共有<em class="red fb ml5px mr5px" id="count1"></em>条数据</span>
                                    </p>
                                </div>
                                <div class="border1px border-radius4 relative" id="data1">
                                    <table class="layui-hide" id="test1" lay-filter="test"></table>
                                </div>
                            </article>
                            <!-- 药物入库列表-空状态 -->
                            <article style="display: none" id="kong1">
                                <dl class="textCenter">
                                    <dt><img src="../static/img/kong.png" alt=""></dt>
                                    <!--                                    <dd class="gray mt20px">暂无数据</dd>-->
                                </dl>
                            </article>
                        </div>
                        <div class="layui-tab-item" id="2">
                            <!-- 药物发放-查看 -->
                            <article>
                                <div class="lh32px mb20px overflow add-btn-input">
                                    <p class="left cursor">
                                        <span class="white border-radius4 bgGreen inline-block pl15px pr15px" onclick="addGrant()"><img src="../static/img/button_add.png">添加药物发放</span>
                                        <span class="white border-radius4 bgGreen inline-block pl15px pr15px mr25px ml25px" onclick="downloadGrantExcel()"><img src="../static/css/staff/img/icon_daochu.png">下载自备药品发放表</span>
                                    </p>
                                    <p class="right" id="c2">
                                        <span>共有<em class="red fb ml5px mr5px" id="count2">36</em>条数据</span>
                                    </p>
                                </div>
                                <div class="border1px border-radius4 relative" id="data2">
                                    <table class="layui-hide" id="test2" lay-filter="test"></table>
                                </div>
                            </article>
                            <!-- 药物发放-空状态 -->
                            <article style="display: none" id="kong2">
                                <dl class="textCenter">
                                    <dt><img src="../static/img/kong.png" alt=""></dt>
                                    <!--                                    <dd class="gray mt20px">暂无数据</dd>-->
                                </dl>
                            </article>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<!--弹层-->
<div id="pop-nursingLevelPicLayerOpen" style="display: none;">
    <div class="pop-up">
        <!-- 查看护理等级 -->
        <div>
            <div class="pop-title relative overflow mb15px">
                <span class="ml15px">护理等级</span>
                <p class="right"><img src="../static/elderlyInfo/img/close_icon.png" class="block pop-close cursor">
                <p>
            </div>
            <div class="mt10px">
                <p><img id="nursingPic" src="" alt=""></p>
                <!-- <p><img src="../static/elderlyInfo/img/zhong_img.png" alt=""></p>
                <p><img src="../static/elderlyInfo/img/zhongdu_img.png" alt=""></p> -->
            </div>
        </div>
    </div>
</div>

<script src="../static/js/jquery-2.1.3.min.js"></script>
<script src="../static/layui/layui.js" charset="utf-8"></script>
<script th:inline="javascript">

    var userNo = [[${userNo}]]

    $(function () {

        var flag = [[${flag}]]
        if (flag == 2) {
            $("#4").addClass('layui-this').siblings().removeClass('layui-this');
            $("#2").addClass('layui-show').siblings().removeClass('layui-show');
        }

        $(".return").click(function () {
            window.history.back();
        })

        getData();

        //头部老人信息
        getElderlyUserInfo();
    });

    function getData() {
        //左侧菜单栏
        layui.use(['element', 'form', 'table'], function () {
            var element = layui.element;
            var form = layui.form;
            var table = layui.table;
            var currentTime = new Date();
            var currentDate = currentTime.toLocaleDateString();
            console.log(currentDate)
            //第一个实例
            table.render({
                elem: '#test1'
                , url: "../medicine/getUserMedicineByUserNo"
                , where: {userNo: userNo}
                , request: {
                    pageName: 'currentPage' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                //,count: 10  //数据总数，从服务端得到
                //,data: listData
                , page: true //开启分页
                , limit: 10 //每页显示的条数
                //,limits:[3,4,5]
                , groups: 9 //连续页码个数
                , parseData: function (res) {
                    console.log(res);
                    return {
                        "code": res.code,
                        "data": res.data.records,
                        "count": res.data.total,
                        "limit": res.data.size,
                    };
                },
                cols: [
                    [ //表头
                        {
                            title: '序号',
                            type: 'numbers',
                            width: 80,
                            fixed: 'left',
                        }, {
                        field: 'meicineName',
                        title: '药物名称',
                        templet: function (res) {
                            console.log(res);
                            var html = "<div class='table-add-btn'><em>" + res.meicineName + "</em>"
                            if (res.meicineNature == 102) {
                                html += "<span class='span-bgYellow'>精神药物</span>";
                            }
                            html += "</div>";
                            return html;
                        }
                    }, {
                        field: 'createDate',
                        title: '登记时间',
                    }, {
                        field: 'validityDate',
                        title: '有效期',
                        templet: function (res) {
                            console.log(res);
                            //转换时间
                            var html = "<div class='table-add-btn'><em>" + res.validityDate + "</em>"
                            if (res.is_guoQi == 2) {
                                html += "<span class='border-bgred'>过期</span>";
                            }
                            html += "</div>";
                            return html;
                        }
                    }, {
                        field: 'userEndDtate',
                        title: '药量结束时间',
                        templet: function (res) {
                            console.log(res);
                            //转换时间
                            if (isNull(res.userEndDtate)) {
                                res.userEndDtate = "";
                            }
                            var html = "<div class='table-add-btn'><em>" + res.userEndDtate + "</em>"
                            if (res.is_end == 2) {
                                html += "<span class='border-bgblue'>用完</span>";
                            }
                            html += "</div>";
                            return html;
                        }
                    }, {
                        field: 'tellerNo',
                        title: '经办人',

                    }, {
                        title: '操作',
                        style: 'color:#1C9399;',
                        fixed: 'right',
                        width: 140,
                        templet: function (res) {
                            console.log(res);
                            return "<div class='table-list-btn'><span class='cursor' onclick=\"toRegDetails('" + res.id + "')\">查看</span>|<span class='cursor' onclick=\"deleteReg('" + res.id + "')\">删除</span></div>"
                        }

                    }
                    ]
                ], done: function (res, curr, count) {
                    $("#count1").text(count);
                    if (count == 0) {
                        $("#kong1").css("display", "");
                        $("#c1").css("display", "none");
                        $("#data1").css("display", "none");
                    }

                }
            });

            //第一个实例
            table.render({
                elem: '#test2'
                , url: "../meicinedistribution/getgetMeicineDistributionByIdByUserNo"
                , where: {userNo: userNo}
                , request: {
                    pageName: 'currentPage' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                //,count: 10  //数据总数，从服务端得到
                //,data: listData
                , page: true //开启分页
                , limit: 10 //每页显示的条数
                //,limits:[3,4,5]
                , groups: 9 //连续页码个数
                , parseData: function (res) {
                    console.log(res);
                    return {
                        "code": res.code,
                        "data": res.data.records,
                        "count": res.data.total,
                        "limit": res.data.size,
                    };
                },
                cols: [
                    [ //表头
                        {
                            title: '序号',
                            type: 'numbers',
                            width: 80,
                            fixed: 'left',
                        }, {
                        field: 'meicineName',
                        title: '药物名称',
                    }, {
                        field: 'meicineDosage',
                        title: '剂量',
                    }, {
                        field: 'morningCount',
                        title: '早8',
                    }, {
                        field: 'noonCount',
                        title: '中12',
                    }, {
                        field: 'afternoonCount',
                        title: '下4',

                    }, {
                        field: 'nightCount',
                        title: '晚8',
                    }, {
                        field: 'startDate',
                        title: '开始日期',
                    }, {
                        field: 'endDate',
                        title: '结束日期',
                    }, {
                        field: 'flag',
                        title: '发放状态',

                    }, {
                        field: 'city',
                        title: '操作',
                        style: 'color:#1C9399;',
                        fixed: 'right',
                        width: 140,
                        templet: function (res) {
                            console.log(res);
                            return "<div class='table-list-btn'><span class='cursor' onclick=\"toGrantDetails('" + res.id + "')\">查看</span>|<span class='cursor' onclick=\"deleteGrant('" + res.id + "')\">删除</span></div>"
                        }

                    }
                    ]
                ], done: function (res, curr, count) {
                    $("#count2").text(count);
                    if (count == 0) {
                        $("#kong2").css("display", "");
                        $("#c2").css("display", "none");
                        $("#data2").css("display", "none");
                    }
                }
            });
        });
    }


    function addGrant() {
        window.location.href = "../meicinedistribution/toAddMeicineDistribution?userNo=" + userNo
    }

    function register() {
        window.location.href = "../medicine/toAddMedicinePage?userNo=" + userNo
    }

    function toRegDetails(id) {
        window.location.href = "../medicine/toRegDetails?id=" + id
    }

    function toGrantDetails(id) {
        window.location.href = "../meicinedistribution/toMeicineDetails?id=" + id
    }


    function deleteReg(id) {
        var data = {id: id};
        layer.confirm('是否删除该信息', {
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll();
            $.ajax({
                url: "../medicine/deleteById",
                type: "delete",
                async: false,
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg);
                        getData();
                    } else {
                        layer.msg(result.msg);
                    }
                }
            })
        });
    }

    function deleteGrant(id) {
        var data = {id: id};
        layer.confirm('是否删除该信息', {
            btn: ['确定', '取消']
        }, function () {
            layer.closeAll();
            $.ajax({
                url: "../meicinedistribution/deleteById",
                type: "delete",
                async: false,
                dataType: "json",
                data: data,
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg);
                        getData();
                    } else {
                        layer.msg(result.msg);
                    }
                }
            })
        });
    }


    function getElderlyUserInfo() {
        var data = {userNo: userNo};
        $.ajax({
            url: "../medicine/getElderlyUserInfo",
            type: "get",
            async: false,
            dataType: "json",
            data: data,
            success: function (data) {
                if (data.code == 200) {
                    if (data.data.cognitionStatus == 1) {
                        $("#cognitionStatus").css("display", "");
                    }
                    if (isNull(data.data.headUrl)) {
                        $("#headUrl").attr("src", "../static/img/defaultHead.jpg")
                    } else {
                        $("#headUrl").attr("src", data.data.headUrl)
                    }
                    $("#userName").text(data.data.userName)
                    $("#userSex").text(data.data.userSex)
                    $("#userAge").text(data.data.userAge)
                    $("#securityType").text(data.data.securityType)
                    $("#eduction").text(data.data.eduction)
                    $("#userAddress").text(data.data.userAddress)
                    $("#bedInfo").text(data.data.bedInfo)
                    $("#nursingDegree").text(data.data.nursingDegree)
                    $("#assessmentDegree").text(data.data.assessmentDegree)
                    $("#contractEndDate").text("合同截止：" + data.data.contractEndDate)
                    if (!isNull(data.data.assessmentDate)) {
                        $("#assessmentDate").text("下次护理评估时间：" + data.data.assessmentDate)
                    }
                    if (!isNull(data.data.nursingDate)) {
                        $("#nursingDate").text("下次护理评估时间：" + data.data.nursingDate)
                    }

                    if (!isNull(data.data.nursingImg)) {
                        $("#nursingPic").attr("src", data.data.nursingImg);
                    }

                }
            }
        })
    }


    //护理等级 弹框
    function nursingLevelPicLayerOpen() {
        layer.open({
            type: 1,
            title: false, //不显示标题栏
            closeBtn: false,
            area: ["$('div#pop-con') + width() + 'px'", ''],
            shade: 0.5,
            id: 'nursingLevelPicLayerOpen', //设定一个id，防止重复弹出
            /*,btn: ['确认支付']*/
            btnAlign: 'c',
            moveType: 1, //拖拽模式，0或者1
            shadeClose: true, //设置允许点遮罩关闭
            content: $("div#pop-nursingLevelPicLayerOpen"),
            success: function () {
                //关闭弹层
                $(".pop-close").click(function () {
                    layer.closeAll();
                });
            },
        });
    }

    function downloadGrantExcel() {
        window.location.href = "../excel/exportExcel2?userNo=" + userNo;
    }

    function downloadRegExcel() {
        window.location.href = "../excel/exportRegExcel?userNo=" + userNo;
    }

    function isNull(value) {
        return value == null || value === "" || value === undefined;
    }

</script>
</body>

</html>
